import dayjs from 'dayjs'

/**
 * 每签到天数大于等于7天可提现1元，2元，
 * 每签到天数大于等于14天可提现5元，
 * 每签到天数大于等于28天可提现10元，
 * 每签到天数大于等于60天可提现20元，
 * 其中每天可提现1次
 * 若中断一次，需要重新计算签到天数，每月有1次补签机会
 * 为了获取利益最大化，提现优先级是10元>20元>5元>2元>1元
 * @param startDate 签到开始日期
 * @param endDate 签到结束日期
 * * */
const getMaxMoney = (startDate, endDate) => {
	const dayCount = (new Date(endDate).getTime() - new Date(startDate).getTime()) / (60 * 60 * 24 * 1000) + 1;
	console.log(dayCount);
	let count1 = 0
	let count2 = 0
	let count5 = 0
	let count10 = 0
	let count20 = 0
	let day = 0
	let day7_1 = 0
	let day7_2 = 0
	let day14 = 0
	let day28 = 0
	let day60 = 0
	while (day < dayCount) {
		const currentDate = dayjs(startDate).add(day, 'day').format('YYYY-MM-DD')
		day++
		day7_1++
		day7_2++
		day14++
		day28++
		day60++
		if (day28 >= 28) {
			console.log(currentDate, 10)
			count10++
			day28 = 0
		} else if (day60 >= 60) {
			console.log(currentDate, 20)
			count20++
			day60 = 0
		} else if (day14 >= 14) {
			console.log(currentDate, 5)
			count5++
			day14 = 0
		} else if (day7_2 >= 7) {
			console.log(currentDate, 2)
			count2++
			day7_2 = 0
		} else if (day7_1 >= 7) {
			console.log(currentDate, 1)
			count1++
			day7_1 = 0
		}
		// console.log(day, day7_1, day7_2, day14, day28, day60)
	}

	console.log(`
		提现1元的有${count1}次数，
		提现2元的有${count2}次数，
		提现5元的有${count5}次数，
		提现10元的有${count10}次数，
		提现20元的有${count20}次数，
		总金额为：1*${count1}+${count2}*2+${count5}*5+${count10}*10+${count20}*20 = ${count1 + count2 * 2 + count5 * 5 + count10 * 10 + count20 * 20}	`)
}
getMaxMoney('2024-09-19', '2025-12-31')